#include "stdafx.h"
#include "TinyThreadPool.h"

namespace TinyCC
{


	CTinyThreadPool::CTinyThreadPool(int nMaxThreadCount)
		:m_recHandle( NULL )
	{
		_init();

		_setMaxThreadCount(nMaxThreadCount);
	}

	CTinyThreadPool::~CTinyThreadPool(void)
	{
		_destroy();
	}

	void CTinyThreadPool::_init(void)
	{
		m_nMaxThreadCount=0;
		m_nCurAllThreadCount=0;
		m_nCurWorkThreadCount=0;
		m_hAllDeadEvent=NULL;
		m_hAllDeadEvent=CreateEvent(NULL,true,false,NULL);
	}

	void CTinyThreadPool::_destroy(void)
	{
		CloseHandle(m_hAllDeadEvent);
	}

	void CTinyThreadPool::_incrementCurAllThreadCount(void)
	{
		::InterlockedIncrement((LPLONG)&m_nCurAllThreadCount);
	}


	void CTinyThreadPool::_decrementCurAllThreadCount(void)
	{
		InterlockedDecrement((LPLONG)&m_nCurAllThreadCount);
	}


	void CTinyThreadPool::_setCurAllThreadCount(int nCount)
	{
		InterlockedExchange((LPLONG)&m_nCurAllThreadCount,nCount);
	}


	void CTinyThreadPool::_incrementCurWorkThreadCount(void)
	{
		InterlockedIncrement((LPLONG)&m_nCurWorkThreadCount);
	}


	void CTinyThreadPool::_decrementCurWorkThreadCount(void)
	{
		InterlockedDecrement((LPLONG)&m_nCurWorkThreadCount);
	}


	void CTinyThreadPool::_setCurWorkThreadCount(int nCount)
	{
		InterlockedExchange((LPLONG)&m_nCurWorkThreadCount,nCount);
	}

}